<?php
/**
 * Description: 获取面试试卷列表filter
 * User: devforma
 * Date: 2016/11/14
 * Time: 15:45
 */

class InterviewPaperFilters implements iController {

    /**
     * api请求处理主函数
     * @param array $queryArgs 就是$_REQUEST变量
     * @return array api返回结果，必须含response_code
     */
    public function output($queryArgs) {

        $areas = $this->getArea();
        $years = $this->getYear();
        $notes = $this->getNote();


        $list = ['area' => [], 'year' => [], 'notes' => []];
        foreach ($areas as $a) {
            $list['area'][] = [
                'area_id' => (int)$a->id,
                'area' => $a->name
            ];
        }

        foreach ($years as $y) {
            $list['year'][] = (int)$y;
        }

        foreach ($notes as $n) {
            $list['notes'][] = [
                'note_id' => (int)$n->id,
                'note' => $n->term_name
            ];
        }

        return genOutput(1, $list);
    }

    /**
     * 获取面试知识点列表
     *
     * @return array
     */
    private function getNote() {
        global $cmsdb;

        $sql = 'SELECT `id`, `term_name` FROM `interview_note_term` WHERE `term_type`=1 AND `term_status`=1';

        return (array)$cmsdb->getResults($sql);
    }

    /**
     * 获取面试地区列表
     *
     * @return array
     */
    private function getYear() {
        global $cmsdb;

        $sql = 'SELECT DISTINCT(`year`) FROM `interview_papers`';

        return (array)$cmsdb->getCol($sql);
    }

    /**
     * 获取面试年份
     *
     * @return array
     */
    private function getArea() {
        global $cmsdb;

        $sql = 'SELECT a.id, a.name FROM `interview_area_conf` AS ac INNER JOIN `original_ztk_area` AS a ON ac.area_id=a.id ORDER BY a.id';

        return (array)$cmsdb->getResults($sql);
    }
}